/**
 * Created with IntelliJ IDEA.
 * User: aermakov
 * Date: 24.05.13
 * Time: 18:33
 * To change this template use File | Settings | File Templates.
 */

Ext.ns('GrailsCompany.util');

GrailsCompany.util.RegexValidator = function(value, regex, msg, allowBlank) {
    if (allowBlank === undefined) allowBlank = true;
    if (!value && allowBlank) return true;
    return regex.exec(value) ? true: msg;
}

GrailsCompany.util.CreditCardValidator = function (value) {
    var regex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/;
    return GrailsCompany.util.RegexValidator(value, regex, 'Invalid credit card number');
}